<?php

namespace App\Http\Controllers\Admin;

use App\Http\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\View;

class CommonController extends Controller
{
    public function __construct()
    {
        $category = Category::tree();
        View::share('category',$category);

    }

    // 文件上传
    protected function upload(){
        $file = Input::file('Filedata');
        // 确认上传的文件是否有效
        if($file->isValid()){
            $file_ext = $file->getClientOriginalExtension();
            $new_fileName = time('Ymdhis').'_'.mt_rand(1000,9999).'.'.$file_ext;
            $res = $file->move(base_path().'/uploads/article/',$new_fileName);
            return array('status'=>0,'msg'=>'文件上传成功!','url'=>'article/'.$new_fileName);
        }else{
            return array('status'=>1,'msg'=>'文件上传失败!');
        }

    }
}
